package org.signal.glide;

import android.content.Context;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.model.ModelLoader;
import com.bumptech.glide.load.model.ModelLoaderFactory;
import com.bumptech.glide.load.model.MultiModelLoaderFactory;
import com.bumptech.glide.signature.ObjectKey;
import java.io.InputStream;

public class CustomImageModelLoader implements ModelLoader<CustomImageModel, InputStream> {
    private final Context context;

    public CustomImageModelLoader(Context context) {
        this.context = context;
    }

    @Override
    public LoadData<InputStream> buildLoadData(CustomImageModel model, int width, int height, Options options) {
        return new LoadData<>(new ObjectKey(model), new CustomImageDataFetcher(context, model));
    }

    @Override
    public boolean handles(CustomImageModel model) {
        return true;
    }

    public static class Factory implements ModelLoaderFactory<CustomImageModel, InputStream> {
        private final Context context;

        public Factory(Context context) {
            this.context = context;
        }

        @Override
        public ModelLoader<CustomImageModel, InputStream> build(MultiModelLoaderFactory multiFactory) {
            return new CustomImageModelLoader(context);
        }

        @Override
        public void teardown() {}
    }
} 